package study05;

import java.io.*;

public class Java05_Copy_string_1 {
    public static void main(String[] args) throws Exception {
//        字符串
//        数据源文件
        File srcFile = new File("D:\\java_study\\java_study\\data\\word.txt");
//        数据目的地文件(自动生成文件)
        File destFile = new File("D:\\java_study\\java_study\\data\\test1.txt.copy");
        //    字符输入流
        BufferedReader reader = null;
        //    字符输出流
        PrintWriter writer = null;
        try {
            reader = new BufferedReader(new FileReader(srcFile));
            writer = new PrintWriter(destFile);

//            打开阀门流转数据（输入）
//            读取文件中一行数据
            String line = null;
//            打开阀门流转数据（输出）
//            读取文件中一行数据
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
                writer.println(line);
            }
//            刷写数据
            writer.flush();

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (writer != null) {
                writer.close();
            }
        }
    }
}
